package com.thread;

/**
 * @Auther: zwg
 * @Date: 2019/3/14 11:17
 * @Description:
 */
public class AlternateOut {
    static class RunableTask implements Runnable {
        static int value = 0;

        @Override
        public void run() {
            while (value <= 100) {
                synchronized (RunableTask.class) {
                    System.out.println(Thread.currentThread().getName() + ":" + value++);
                    RunableTask.class.notify();
                    try {
                        RunableTask.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }
    }

    public static void main(String[] args) {
        new Thread(new RunableTask(), "偶数").start();
        new Thread(new RunableTask(), "奇数").start();
    }
}
